﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using EntityFrameworkETL.Interfaces;
using System.Data.SqlClient;

namespace EntityFrameworkETL
{
    public class ExecuteNonQuery : IExecuteNonQuery
    {
        public void Execute(string connectionString, string sql, params System.Data.Common.DbParameter[] parameters)
        {
            if (sql.ToString() != string.Empty)
            {
                using (SqlConnection sqlConn = new SqlConnection(connectionString))
                {
                    using (SqlCommand command = sqlConn.CreateCommand())
                    {

                        command.CommandText = sql.ToString();
                        command.Parameters.AddRange(parameters);
                        sqlConn.Open();
                        command.ExecuteNonQuery();
                        sqlConn.Close();
                    }
                }
            }
        }
    }
}
